import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

import cai from './modules/cai'

import liu from './modules/liu'
import roles from "./modules/roles"
import xiao from './modules/xiao'
import zeng from "./modules/zeng";

const routes: Array<RouteRecordRaw> = [
   
    {
        path:'/login',
        name:'login',
        component:()=>import('@/views/cai/login/index.vue'),
    },
    {
        path:'/',
        name:'home',
        redirect:'/welcome',
        component:()=>import('@/views/Home/index.vue'),
        children:[
            {
                path:'/welcome',
                component:()=>import('@/views/Home/welcome.vue'),
               },
        
            
        ]
    },

]
export const roleRoutes=[
    ...cai,
    ...roles,
    ...liu,
    ...zeng,
    ...xiao, 
]


const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from, next) => {

	// 判断有没有登录
	if (!sessionStorage.getItem('token')) {
		if (to.name == "login") {
          
			next();
		} else {
            
            router.push('login')
       
		}
	} else {
		next();
	}
});
export default router
